﻿(function($jabezPHP){var escapeable=/["\\\x00-\x1f\x7f-\x9f]/g,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},hasOwn=Object.prototype.hasOwnProperty;$jabezPHP.toJSON=function(o){if(o===null){return'null';}
var type=typeof o;if(type==='undefined'){return undefined;}
if(type==='number'||type==='boolean'){return''+o;}
if(type==='string'){return $jabezPHP.quoteString(o);}
if(type==='object'){if(typeof o.toJSON==='function'){return $jabezPHP.toJSON(o.toJSON());}
if(o.constructor===Date){var month=o.getUTCMonth()+1,day=o.getUTCDate(),year=o.getUTCFullYear(),hours=o.getUTCHours(),minutes=o.getUTCMinutes(),seconds=o.getUTCSeconds(),milli=o.getUTCMilliseconds();if(month<10){month='0'+month;}
if(day<10){day='0'+day;}
if(hours<10){hours='0'+hours;}
if(minutes<10){minutes='0'+minutes;}
if(seconds<10){seconds='0'+seconds;}
if(milli<100){milli='0'+milli;}
if(milli<10){milli='0'+milli;}
return'"'+year+'-'+month+'-'+day+'T'+
hours+':'+minutes+':'+seconds+'.'+milli+'Z"';}
if(o.constructor===Array){var ret=[];for(var i=0;i<o.length;i++){ret.push($jabezPHP.toJSON(o[i])||'null');}
return'['+ret.join(',')+']';}
var name,val,pairs=[];for(var k in o){if(!hasOwn.call(o,k)){continue;}
type=typeof k;if(type==='number'){name='"'+k+'"';}else if(type==='string'){name=$jabezPHP.quoteString(k);}else{continue;}
type=typeof o[k];if(type==='function'||type==='undefined'){continue;}
val=$jabezPHP.toJSON(o[k]);pairs.push(name+':'+val);}
return'{'+pairs.join(',')+'}';}};$jabezPHP.evalJSON=typeof JSON==='object'&&JSON.parse?JSON.parse:function(src){return eval('('+src+')');};$jabezPHP.secureEvalJSON=typeof JSON==='object'&&JSON.parse?JSON.parse:function(src){var filtered=src.replace(/\\["\\\/bfnrtu]/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,'');if(/^[\],:{}\s]*$jabezPHP/.test(filtered)){return eval('('+src+')');}else{throw new SyntaxError('Error parsing JSON, source is not valid.');}};$jabezPHP.quoteString=function(string){if(string.match(escapeable)){return'"'+string.replace(escapeable,function(a){var c=meta[a];if(typeof c==='string'){return c;}
c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+(c%16).toString(16);})+'"';}
return'"'+string+'"';};})(jQuery);

$jabezPHP.config = {

	'debug': {'status': false, 'level': 3},
	'development': {'status': false},
	'jabezWebDeveloperIsActive': false,
	'element': {},
	'data': {'value': {}, 'method': 'append', 'isObject': false},
	'webDeveloper': {'inputUuid': null, 'outputUuid': null, 'method': null, 'codeElement': null, 'version': null, 'encoding': 'UTF-8'}
};

$jabezPHP.webDeveloper = {

	'methods': {},
	'callBacks': {}
};

$jabezPHP.fn.extend({

  	clearFields: function() {

  		$jabezPHP('> *', this).val('');

  		$jabezPHP('select', this).val('Selecione');

  		$jabezPHP('select[multiple]', this).empty();
 	},

	start: function(params) {

		var paramsDefault = {

			fnc: 'start',
			read: 'document',
			type: 'ready'
		};

		var params = $jabezPHP.extend(paramsDefault, params);

		try {

			if(documentReady == true) {

				eval(params.fnc + '()');
			}

		} catch(e) {

			eval('$jabezPHP('+params.read+').'+params.type+'(function() {'+

				params.fnc + '()'+
			'}, documentReady = true);');		
		}
 	},

	ajaxRequest: function(params){

		var defaultParams = {

			type: 'POST',
			data: {},
			dataType: 'json',
			contentType: 'application/x-www-form-urlencoded',
			scriptCharset: 'UTF-8',
			ifModified: false,
			processData: true,
			global: true,
			cache: true,
			context: document.body,
			jsonp: null,
			password: null,
			username: null,
			async: true,
			controller: false,
			query: false,
			action: false,
			vars: {},
			options: {},
			callBacks: {'shutdown': false, 'beforeSend': false, 'start': false, 'success': false, 'complete': false, 'status': false, 'error': false},
			webDeveloper: false,
			serialized: false,
			time: false,
			element: $jabezPHP(this),
			url: '/jabez-php/index.php',
			timeout: 10000
		};

		var params = $jabezPHP.extend(defaultParams, params);
		params.isForm = false;
		$jabezPHP.config.element = params.element;

		if(params.element.attr('tagName') == 'FORM' || params.element.attr('tagName') == 'form') {

			params.serialized = params.element.serializeArray();
			params.isForm = true;
		}

		if($jabezPHP.config.debug != false) {

			params.time = true;
		}

		if(params.time != false) {

			Datetime = new Date();
			startOfTime = Datetime.getTime();
		}

		if(params.query != false) {

			params.controller = params.query;
		}

		if($jabezPHP.isPlainObject(params.data)) {

			params.vars = $jabezPHP.param(params.data);
		}

		else {

			params.vars = {};
			params.vars = params.data;
			params.data = {};
		}

		var _CoreParamsRequest = {};
		_CoreParamsRequest = {'ajax': true, 'controller': params.controller, 'options': params.options, 'type': params.type, 'contentType': params.contentType, 'charset': params.scriptCharset, 'cache': params.cache, 'dataType': params.dataType, 'params': params.vars, 'serialized': [
		  {
		    name: "a",
		    value: "1"
		  },
		  {
		    name: "b",
		    value: "2"
		  },
		  {
		    name: "c",
		    value: 10.5
		  },
		  {
		    name: "d",
		    value: "%&?4"
		  },
		  {
		    name: "e",
		    value: true
		  }
		], 'isForm': params.isForm, 'timeout': params.timeout, 'username': params.username, 'password': params.password, 'debug': params.debug};

		params.data._CoreConfigRequest = {};
		params.data._CoreConfigRequest.ajax = 1;
		params.data._CoreConfigRequest.data = _CoreParamsRequest;
		params.data = $jabezPHP.toJSON(params.data);

		$jabezPHP.ajax({

			url: params.url,
			type: params.type,
			data: params.data,
			dataType: params.dataType,
			processData: params.processData,
			contentType: params.contentType,
			scriptCharset: params.scriptCharset,
			async: params.async,
			global: params.global,
			cache: params.cache,
			ifModified: params.ifModified,
			jsonp: params.jsonp,
			username: params.username,
			password: params.password,
			context: params.context,
			timeout: params.timeout,

			beforeSend: function(xhr, options) {

				if(params.callBacks.beforeSend != false && !$jabezPHP.isEmptyObject(params.callBacks.beforeSend)) {

					eval(params.callBacks.beforeSend + '(params.element, params, xhr, options)');
				}

				if(params.callBacks.start != false && !$jabezPHP.isEmptyObject(params.callBacks.start)) {

					eval(params.callBacks.start + '(params.element, params, xhr, options)');
				}
			},

			success: function(data){
				
				$jabezPHP.config.data.value = data;

				if(params.callBacks.success != false && !$jabezPHP.isEmptyObject(params.callBacks.success)) {

					eval(params.callBacks.success + '(data, params.element, params)');

					if(params.callBacks.shutdown != false && !$jabezPHP.isEmptyObject(params.callBacks.shutdown)) {

						if(params.callBacks.shutdown == true) {

							eval(params.controller + '(data, params.element, params)');
						}

						else {

							eval(params.callBacks.shutdown + '(data, params.element, params)');
						}
					}

					return;
				}

				if(params.debug == true) {

					//$jabezPHP(params.element).empty().append(data[0]);
					//alert(data);
				}

				else {

					if(params.controller == false) {

						$jabezPHP(params.element).empty().append(data);
					}

					else {

						if(params.callBacks.shutdown != false && !$jabezPHP.isEmptyObject(params.callBacks.shutdown)) {

							if(params.callBacks.shutdown == true) {

								eval(params.controller + '(data, params.element, params)');
							}

							else {

								eval(params.callBacks.shutdown + '(data, params.element, params)');
							}
						}

						else {

							if(params.element.attr('tagName') == 'SELECT' || params.element.attr('tagName') == 'select') {

								$jabezPHP(params.element).empty().append(data);
							}

							else {

								$jabezPHP(params.element).val(data);
							}
						}
					}
				}

				if(params.time != false) {

					Date = new Date();
					//alert((Date.getTime() - startOfTime) / 1000);
				}
			},

			complete: function(xhr, textStatus){

				if(params.callBacks.complete != false && !$jabezPHP.isEmptyObject(params.callBacks.complete)) {

					eval(params.callBacks.complete + '(dataOfReturn, params.element, params, xhr, textStatus)');
				}
			},

			error: function(xhr, options, throwError) {

				if(params.callBacks.error != false && !$jabezPHP.isEmptyObject(params.callBacks.error)) {

					eval(params.callBacks.error + '(dataOfReturn, params.element, params, xhr, options, throwError)');
				}

				else {

					alert('Error: problem in the execution of the request.' + "\n" + throwError);
				}

				if(params.time != false) {

					Datetime = new Date();
					//alert((Datetime.getTime() - startOfTime) / 1000);
				}
			}
		});
	}
});

function teste(a, b, c) {

	//alert('hjlhhuuuuuk');
}

$jabezPHP.webDeveloper.callBacks.afterAjaxResponse = function(a, b, c) {

	alert(a.response.data);
};
//Redimensionar SWF - SwfFit 2.3
//var swffit=function(){var win=window,doc=document,html=doc.getElementsByTagName("html")[0],AGENT=navigator.userAgent.toLowerCase(),WK=/webkit/.test(AGENT),IE=/msie/.test(AGENT)&&!win.opera,FF=/firefox/.test(AGENT)&&!win.opera,UNDEF="undefined",_ft,_re,_t,_mw,_mh,_xw,_xh,_hc,_vc,_ow,_oh;swfobject.createCSS("object","position:absolute; outline:none");function fit(t,mw,mh,xw,xh,hc,vc){mw=mw||_ow;mh=mh||_oh;xw=xw||null;xh=xh||null;hc=(hc||hc==null);vc=(vc||vc==null);configure({target:t,minWid:mw,minHei:mh,maxWid:xw,maxHei:xh,hCenter:hc,vCenter:vc});}function configure(o){var evalNum=function(v,p){return(typeof o[p]!=UNDEF)?o[p]:v;},evalBool=function(v,p){return(o[p]||(v&&typeof o[p]==UNDEF));};_mw=evalNum(_mw,"minWid");_mh=evalNum(_mh,"minHei");_xw=evalNum(_xw,"maxWid");_xh=evalNum(_xh,"maxHei");_hc=evalBool(_hc,"hCenter");_vc=evalBool(_vc,"vCenter");if(o.target&&(o.target!=_t)){_t=o.target;swfobject.addDomLoadEvent(initFit);if(IE){swfobject.addLoadEvent(initFit);}}else{startFit();}}function initFit(){if(!html.style.overflowX){controlScroll(0,0);}if(!html.style.overflowY){controlScroll(0,1);}html.style.height=doc.body.style.height="100%";doc.body.style.margin=doc.body.style.padding=0;var st="width:100%; height:100%";st+=(IE)?"; overflow:hidden":"";swfobject.createCSS("#"+_t,st);_ft=doc.getElementById(_t);_ft=(_ft!=UNDEF&&FF&&/object/.test(_ft.innerHTML))?doc.getElementById(_t).getElementsByTagName("object")[0]:_ft;_ow=_ft.width;_oh=_ft.height;_mw=_mw||_ow;_mh=_mh||_oh;startFit();}function startFit(){setSize();if(!_re){swffit.addResizeEvent(setSize);_re=1;}}function stopFit(w,h){if(_re){swffit.removeResizeEvent(setSize);_re=0;setStyle("top","auto");setStyle("left","auto");setStyle("marginTop",0);setStyle("marginLeft",0);w=w||"100%";h=h||"100%";setWidth(w);setHeight(h);forceRedraw();}}function forceRedraw(){if(WK){html.focus();}}function controlResizeEvent(a,fn){var p=(a)?["addEventListener","attachEvent"]:["removeEventListener","detachEvent"];if(win[p[0]]){win[p[0]]("resize",fn,false);}else{if(win[p[1]]){win[p[1]]("onresize",fn);}}}function setWidth(w){var v=(isNaN(w))?w:w+"px";setStyle("width",v);}function setHeight(h){var v=(isNaN(h))?h:h+"px";setStyle("height",v);}function setStyle(p,v){_ft.style[p]=v;}function setSize(){var iw=(win.innerWidth)?win.innerWidth:((doc.documentElement.clientWidth)?doc.documentElement.clientWidth:doc.body.clientWidth),ih=(win.innerHeight)?win.innerHeight:((doc.documentElement.clientHeight)?doc.documentElement.clientHeight:doc.body.clientHeight);iw-=(!IE&&ih<=_mh)?18:0;ih-=(!IE&&iw<=_mw)?18:0;if(_xw&&iw>=_xw){setWidth(_xw);setPosition(0,1);}else{if(iw>_mw&&(iw<_xw||!_xw)){setWidth("100%");}else{setWidth(_mw);}setPosition(0,0);}if(_xh&&ih>=_xh){setHeight(_xh);setPosition(1,1);}else{if(ih>_mh&&(ih<_xh||!_xh)){setHeight("100%");}else{setHeight(_mh);}setPosition(1,0);}forceRedraw();}function setPosition(t,x){var p,m;if(t){p=(x&&_vc)?"50%":"auto";m=(x&&_vc)?-(_xh*0.5)+"px":0;setStyle("top",p);setStyle("marginTop",m);}else{p=(x&&_hc)?"50%":"auto";m=(x&&_hc)?-(_xw*0.5)+"px":0;setStyle("left",p);setStyle("marginLeft",m);}}function controlScroll(s,v){var p=(v)?"overflowY":"overflowX";html.style[p]=(s)?"scroll":"auto";}function getValueOf(p){var o={target:_t,minWid:_mw,minHei:_mh,maxWid:_xw,maxHei:_xh,hCenter:_hc,vCenter:_vc};return o[p];}return{fit:fit,configure:configure,startFit:startFit,stopFit:stopFit,getValueOf:getValueOf,addResizeEvent:function(fn){controlResizeEvent(1,fn);},removeResizeEvent:function(fn){controlResizeEvent(0,fn);},showScrollH:function(){controlScroll(1,0);},showScrollV:function(){controlScroll(1,1);}};}();
/*
$jabezPHP(document).ready(function(){

	$jabezPHP.config.development.status = true;
	$jabezPHP.config.debug.status = true;
	$jabezPHP.config.jabezWebDeveloperIsActive = true;
	//$jabezPHP('#teste').ajaxRequest({query: '.Teste.ControllerTeste2::add/3/2/1', callBacks: {'success': '$jabezPHP.webDeveloper.callBacks.afterAjaxResponse', 'shutdown': 'teste'}, options: ['sendAll'], data: ['éão', {0:true}], debug: true});
	//alert($jabezPHP.config.data.value);
	
	$jabezPHP("#ok").click(function(){
		
		$window = window;
		
		console.log($window);
		//$jabezPHP('#teste').ajaxRequest({query: '.Teste.ControllerTeste2::add/3/2/1', callBacks: {'success': '$jabezPHP.webDeveloper.callBacks.afterAjaxResponse', 'shutdown': 'teste'}, options: ['sendAll'], data: {}, autoResponse: false, debug: true});
		//alert($jabezPHP.toJSON(jQuery));
		//alert($(this).attr("uuid"));
	});
});*/